#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ = ''
__author__ = 'tyh'
__mtime__ = '18-10-16'
# code is far away from bugs with the god animal protecting ~
"""
from drf_haystack.serializers import HaystackSerializer
from rest_framework import serializers

from goods.models import GoodsCategory, GoodsChannel, SKU
from goods.search_indexes import SKUIndex


class GoodsCategorySerialize(serializers.ModelSerializer):

	class Meta:
		model = GoodsCategory
		fields = ('name',)


class GoodsChannelSerialize(serializers.ModelSerializer):
	category = serializers.StringRelatedField()

	class Meta:
		model = GoodsChannel
		fields = ('url', 'category')


class SKUSerializer(serializers.ModelSerializer):

	class Meta:
		model = SKU
		fields = '__all__'


class SKUIndexSerializer(HaystackSerializer):
	"""
	SKU索引结果数据序列化器
	"""
	object = SKUSerializer(read_only=True)

	class Meta:
		index_classes = [SKUIndex]
		fields = ('text', 'object')
